# Tem IRC builtin functions
# Tem version: 0.3
# Description:
# These are small builtin functions for the tem bots functionality. 

# Used for all terminal printing!!
def prnt(msg)
	if $daemonize == 0
		puts msg
	else
		# We'll print the message to a logfile instead.
		if !$logging
			if !$logfile
				$logfile = './tem.log'
			end
			file_handle_ = File.open($logfile, 'a')
			time_ = Time.now.strftime('%c')
			file_handle_.write("Starting logging at "+time_+"...\n") 
			$logging = 1
			file_handle_.close()
		end
		file_handle_ = File.open($logfile, 'a')
		if file_handle_
			if msg == "Exit"
				time_ = Time.now.strftime('%c')
				file_handle_.write("Finishing logging (Tem Exiting) at "+time_+"...\n")
				file_handle_.close()
			else
				msg = msg.chomp
				file_handle_.write(msg+"\n")
				file_handle_.close()
			end
		end
	end
end


def getAuthHost(full_host)
	full_host[0] =  "" # Remove server appended : 
	host = full_host.split("!") # Split at ! so they can change nick.
	return host[1]
end